<template>
  <div>
    <el-select v-model="name" @change="handleChange" style="width: 100%" :placeholder="placeholder">
      <el-option
          v-for="item in options"
          :key="item.supplierId"
          :label="item.supplierName"
          :value="item.supplierId">
      </el-option>
    </el-select>
  </div>
</template>

<script>
import {getInsuranceSelectList} from "@/api/cwgd/insuranceSelect";


export default {
  name: 'index',
  props: {
    companyId: {
      type: String,
      default: ''
    },
    businessTypeCode: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: ''
    }
  },
  computed: {},
  watch: {
    companyId: {
      handler(val) {
        if (val) {
          this.name = val
        }
      },
      immediate: true,
      deep: true,

    }
  },
  data() {
    return {
      options: [],
      name: this.companyId,
    };
  },
  created() {
    this.handleList(this.businessTypeCode)
  },
  mounted() {
  },
  methods: {
    handleList(val) {
      getInsuranceSelectList({businessTypeCode: val}).then(res => {
        if (res.code === 200) {
          this.options = res.data
        }
      })
    },
    handleChange(val) {
      this.ids = val
      let index = this.options.findIndex(a => a.supplierId === val)
      if (index !== -1) {
        this.codes = this.options[index].supplierCode
      }
      let obj = {
        code: this.options[index].supplierCode,
        name: this.options[index].supplierName,
        id: this.options[index].supplierId,
      }
      this.$emit('change', obj)
    }
  },
};
</script>

<style scoped lang=""></style>


